# -*- coding: utf-8 -*-

import os
import sys
import json
import requests
import time
from Log import Log
from Brain import XiaolanBrain

class ClientCommandDo(XiaolanBrain):

    def __init__(self):

        pass

    def dataSkillOut(self):

        """
        技能主要信息分离
        :return:
        """

        Skill = self.data['ClientEvent']['ConversationInfo']['ShouldHandlerSkill']
        AwakenKeyword = self.data['ClientEvent']['ConversationInfo']['SkillAwakenKeyword']
        SkillIntent = self.data['ClientEvent']['ConversationInfo']['SendToSkillInfo']['Intent']
        SkillSlots = self.data['ClientEvent']['ConversationInfo']['SendToSkillInfo']['Slots']
        WordLexer = self.data['ClientEvent']['ConversationInfo']['SendToSkillInfo']['WordLexer']
        Text = self.data['ClientEvent']['ConversationInfo']['SendToSkillInfo']['Text']
        SkillDate = self.data['ClientEvent']['ConversationInfo']['SendToSkillInfo']['SkillDate']
        ConversationMainInfo = {
            'Skill': Skill,
            'Keyword': AwakenKeyword,
            'Intent': SkillIntent,
            'WordLexer': WordLexer,
            'Slots': SkillSlots,
            'SkillDate': SkillDate,
            'Text': Text
        }
        self.Log.addLog("TimeStamp:" + str(ConversationMainInfo['TimeStamp']), 'debug')
        self.Log.addLog("Skill:" + ConversationMainInfo['Skill'], 'debug')
        self.Log.addLog("Intent:" + ConversationMainInfo['Intent'], 'debug')
        self.Log.addLog("WordLexer" + ConversationMainInfo['WordLexer'], 'debug')
        self.Log.addLog("Text:" + ConversationMainInfo['Text'], 'debug')
        return ConversationMainInfo

    def dataLogOut(self):

        """
        Log分离
        :return:
        """

        TimeStamp = self.data['ClientEvent']['Header']['TimeStamp']
        ClientId = self.data['ClientEvent']['Header']['ClientId']
        ClientType = self.data['ClientEvent']['Header']['RequestsFrom']
        NameSpace = self.data['ClientEvent']['Header']['NameSpace']
        LogMainInfo = {
            'NameSpace': NameSpace,
            'ClientId': ClientId,
            'ClientType': ClientType,
            'TimeStamp': TimeStamp
        }
        self.Log.addLog("NameSpace:" + LogMainInfo['NameSpace'], 'debug')
        self.Log.addLog("ClientId:" + LogMainInfo['ClientId'], 'debug')
        self.Log.addLog("ClientType:" + LogMainInfo['ClientType'], 'debug')
        return LogMainInfo

    def dataSlotsOut(self):

        """
        特殊情况槽位信息分离
        :return:
        """

        SlotsInfo = {}
        a = 0
        while 1 == 1:
            if a < len(self.data['ClientEvent']['ConversationInfo']['SendToSkillInfo']['Slots']) + 1:
                SlotsInfo[self.data['ClientEvent']['ConversationInfo']['SendToSkillInfo']['Slots'][a]['slotname']] = self.data['ClientEvent']['ConversationInfo']['SendToSkillInfo']['Slots'][a]['value']
                a = a + 1
            else:
                break
        else:
            pass
        return SlotsInfo